<?php
/**
 * @file Statement.php
 *
 * Abstract for representation of SQL-Statements
 *
 * This abstract class contains some common functions that are often used on
 * SQL-Statements.
 *
 * http://code.google.com/p/rpd/wiki/Statement.php
 *
 * New BSD License
 * \n
 * Copyright (c) 2010 Rpd-Team
 *
 * @namespace  rpd
 * @since      0.0.1
 * @version    0.0.1
 */

/**
 *
 * Iterateable statement representation.
 *
 * With this class it's possible to iterate over the result of a dispatched
 * query.
 *
 * @author RMP
 *
 */
abstract class Db_Statement_Abstract
{
	protected $_line = 0,
	          $_statement = "",
	          $_result = NULL,
	          $_error = array("code"    => NULL,
	                          "message" => NULL),
	          $_connectionOpen = true,
	          $_map = array(),
	          $_statementName = "",
	          $_link = NULL,
	          $_valid = false,
	          $_current = array();
	          
	function current($field = NULL)
	{
		if ($field === NULL)
		{
			return $this->_current;
		}

		return $this->_current[$field];
	}

	function __construct($statement, $link)
	{
		$this->_statement = $statement;
		$this->_link = $link;
	}
	
	/**
	 * Error code to SQL statement
	 *
	 * Gives the error number (defined by used adapter) if an query fails.
	 *
	 * @since 0.2.0
	 *
	 * @return \c int Error number
	 *
	 * @section Examples
	 *
	 * @subsection Db_Statement.errorCode-Show_error Show error
	 *
	 * <pre>/app/Controller/index.php</pre>
	 * @code
	 * <?php
	 *
	 * // get connection to database
	 * $db = new Db();
	 * 
	 * // run some strange query
	 * $statement = $db->query("SELECT 1 WHERE FROM bad_syntax");
	 * 
	 * // check if it didn't worked
	 * if ( !$statement->valid() )
	 * {
	 * 	echo $statement->errorCode();		// show the according error number
	 * }
	 *
	 * ?>
	 * @endcode
	 * \note{ Use Db_Statement::errorMessage for development,
	 *        It will give you a description of the error instead of a number
	 * }
	 *
	 * @see Db::query
	 * @see Db_Statement::errorMessage
	 * @see Db_Statement::valid
	 */
	function errorCode() {}
	
	/**
	 * Error description to a SQL statement
	 *
	 * Returns the error message (defined by used adapter) if an query fails.
	 *
	 * @since 0.2.0
	 *
	 * @return \c string Error message
	 *
	 * @section Examples
	 *
	 * @subsection Db_Statement.errorMessage-Show_error Show error
	 *
	 * <pre>/app/Controller/index.php</pre>
	 * @code
	 * <?php
	 *
	 * // get connection to database
	 * $db = new Db();
	 * 
	 * // run some strange query
	 * $statement = $db->query("SELECT 1 WHERE FROM bad_syntax");
	 * 
	 * // check if it didn't worked
	 * if ( !$statement->valid() )
	 * {
	 * 	echo $statement->errorMessage();		// show the mistake
	 * }
	 *
	 * ?>
	 * @endcode
	 *
	 * @see Db::query
	 * @see Db_Statement::errorCode
	 * @see Db_Statement::valid
	 */
	function errorMessage() {}
}

?>